﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SampleWinProject.Lambda;

namespace SampleWinProject.DesignPartten.Observer
{
    class WeatherData: Subject
    {
        private List<Observer> observers;
        private float temp, humdity, pressure;

        public WeatherData()
        {
            observers = new List<Observer>();
            
        }

        #region Subject Members

        public void RegisterObserver(Observer o)
        {
            observers.Add(o);
        }

        public void RemoveObserver(Observer o)
        {
            observers.Remove(o);
        }

        public void NotifyObservers()
        {
            foreach(Observer o in observers)
            {
                o.Update(temp, humdity, pressure);
            }
        }

        #endregion

        public void MeasurementsChanged()
        {
            NotifyObservers();
        }


        public void SetMeasurements(float temp, float humdity, float pressure)
        {
            this.temp = temp;
            this.pressure = pressure;
            this.humdity = humdity;
            MeasurementsChanged();
        }
    }
}
